import sun.reflect.generics.tree.Tree;

import java.util.Stack;

class TreeNode1 {
    int val;
    TreeNode1 left;
    TreeNode1 right;
    TreeNode1() {}

    TreeNode1(int val) {
        this.val = val;
    }

    TreeNode1(int val, TreeNode1 left, TreeNode1 right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }

    public void prevOrderNor(TreeNode1 root) {
        Stack<TreeNode1> stack = new Stack<>();
        TreeNode1 cur = root;
        while (!stack.isEmpty() || cur != null) {
            while (cur != null) {
                System.out.print(cur.val + " ");
                stack.push(cur);
                cur = cur.left;
            }

            TreeNode1 top = stack.pop();
            cur = top.right;
        }
    }


}


public class Prefrom {
    
}
